import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
///展示文章网页端
class PageWeb extends StatefulWidget {
  final String title;
  final String webUrl;

  PageWeb({this.title, this.webUrl});

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    print(webUrl);
    return PageWebState();
  }
}

class PageWebState extends State<PageWeb> {
  bool isLoading = true;

  final plugin = new FlutterWebviewPlugin();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    plugin.onStateChanged.listen((state) {
      if (state.type == WebViewState.finishLoad) {
        setState(() {
          isLoading = false;
        });
      } else if (state.type == WebViewState.startLoad) {
        setState(() {
          isLoading = true;
        });
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build

    print(widget.webUrl);

    return WebviewScaffold(
      url: widget.webUrl,
      appBar: AppBar(
        title: Text(widget.title),
        bottom: PreferredSize(
          preferredSize: Size.fromHeight(1.0),
          child: isLoading
              ? LinearProgressIndicator()
              : Divider(
                  height: 1.0,
                  color: Theme.of(context).accentColor,
                ),
        ),
      ),
    );
  }
}
